package org.hamster.multidropbox.dropbox.vo
{
	import flash.display.Loader;
	
	import org.hamster.dropbox.models.DropboxFile;
	import org.hamster.multidropbox.main.vo.IStorableVO;

	public class AppDropboxFile extends DropboxFile implements IStorableVO
	{
		private var _client:AppDropboxClient;
		private var _loader:*;
		
		public function set loader(value:*):void
		{
			this._loader = value;
		}
		
		public function get loader():*
		{
			return _loader;
		}
		
		public function get client():AppDropboxClient
		{
			return _client;
		}
		
		public function AppDropboxFile(dropboxClient:AppDropboxClient, dropboxFile:DropboxFile = null)
		{
			this._client = dropboxClient;
			
			if (dropboxFile) {
				this.bytes 			= dropboxFile.bytes;
				this.contents 		= dropboxFile.contents;
				this.hash 			= dropboxFile.hash;
				this.icon 			= dropboxFile.icon;
				this.isDeleted 		= dropboxFile.isDeleted;
				this.isDir 			= dropboxFile.isDir;
				this.mimeType 		= dropboxFile.mimeType;
				this.modified 		= dropboxFile.modified;
				this.path 			= dropboxFile.path;
				this.rev 			= dropboxFile.rev;
				this.revision 		= dropboxFile.revision;
				this.root 			= dropboxFile.root;
				this.size 			= dropboxFile.size;
				this.thumbExists 	= dropboxFile.thumbExists;
			}
		}
		
		public function encodeXML():XML
		{
			var result:XML = <file bytes={bytes}
								   hash={hash}
								   icon={icon}
								   is-deleted={isDeleted}
								   is-dir={isDir}
								   mime-type={mimeType}
								   modified={modified}
								   path={path}
								   rev={rev}
								   revision={revision}
								   root={root}
								   size={size}
								   thumbExists={thumbExists}>
							  </file>;
			return result;
		}
		
		public function decodeXML(value:XML):void
		{
			this.bytes = value.attribute('bytes');
			this.hash =  value.attribute('hash');
			this.icon =  value.attribute('icon');
			this.isDeleted =  value.attribute('is-deleted') == "true";
			this.isDir =  value.attribute('is-dir') == "true";
			this.mimeType =  value.attribute('mime-type');
			this.modified =  value.attribute('modified');
			this.path =  value.attribute('path');
			this.revision =  value.attribute('revision');
			this.root =  value.attribute('root');
			this.size =  value.attribute('size');
			this.thumbExists =  value.attribute('thumb-exists');
		}
	}
}